package reflect.hhh;

import reflect.annotations.AutoRunClass;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) throws Exception{
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个类的完全限定名:");
        String qname = scan.nextLine();
        Class cls=Class.forName(qname);
        boolean mark=cls.isAnnotationPresent(AutoRunClass.class);
        if(mark){
            Object obj=cls.newInstance();
            Field field=cls.getDeclaredField("name");
            field.setAccessible(true);
            field.set(obj,"奥特曼");
            field=cls.getDeclaredField("age");
            field.setAccessible(true);
            field.set(obj,88);
            System.out.println(obj);
        }
        else{
            System.out.println("该类没有被标记为@AutoRunClass");
        }
    }
}
